Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
sox_source.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_sndio/target_sox/roc_sndio/sox_source.h
10//! @brief SoX source.
11
12#ifndef ROC_SNDIO_SOX_SOURCE_H_
13#define ROC_SNDIO_SOX_SOURCE_H_
14
15#include <sox.h>
16
17#include "roc_core/iallocator.h"
19#include "roc_core/stddefs.h"
20#include "roc_core/unique_ptr.h"
21#include "roc_packet/units.h"
22#include "roc_sndio/config.h"
23#include "roc_sndio/isource.h"
24
25namespace roc {
26namespace sndio {
27
28//! SoX source.
29//! @remarks
30//! Reads samples from input file or device.
31//! Supports multiple drivers for different file types and audio systems.
32class SoxSource : public ISource, private core::NonCopyable<> {
33public:
34 //! Initialize.
35 SoxSource(core::IAllocator& allocator, const Config& config);
36
37 virtual ~SoxSource();
38
39 //! Check if the object was successfully constructed.
40 bool valid() const;
41
42 //! Open input file or device.
43 //!
44 //! @b Parameters
45 //! - @p driver is input driver name;
46 //! - @p input is input file or device name, "-" for stdin.
47 //!
48 //! @remarks
49 //! If @p driver or @p input are NULL, defaults are used.
50 bool open(const char* driver, const char* input);
51
52 //! Get sample rate of an input file or a device.
53 virtual size_t sample_rate() const;
54
55 //! Check if the source has own clock.
56 virtual bool has_clock() const;
57
58 //! Get current source state.
59 virtual State state() const;
60
61 //! Wait until the source state becomes active.
62 virtual void wait_active() const;
63
64 //! Read frame.
65 virtual bool read(audio::Frame&);
66
67private:
68 bool prepare_();
69 bool open_(const char* driver, const char* input);
70 void close_();
71
72 sox_format_t* input_;
73 sox_signalinfo_t in_signal_;
74 size_t n_channels_;
75
76 core::IAllocator& allocator_;
77
79 const size_t buffer_size_;
80
81 bool is_file_;
82 bool eof_;
83 bool valid_;
84};
85
86} // namespace sndio
87} // namespace roc
88
89#endif // ROC_SNDIO_SOX_SOURCE_H_
Audio frame.
Definition: frame.h:22
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Unique ownrship pointer.
Definition: unique_ptr.h:27
Source interface.
Definition: isource.h:21
State
Source state.
Definition: isource.h:32
bool open(const char *driver, const char *input)
Open input file or device.
virtual bool has_clock() const
Check if the source has own clock.
virtual bool read(audio::Frame &)
Read frame.
virtual size_t sample_rate() const
Get sample rate of an input file or a device.
virtual State state() const
Get current source state.
SoxSource(core::IAllocator &allocator, const Config &config)
Initialize.
virtual void wait_active() const
Wait until the source state becomes active.
bool valid() const
Check if the object was successfully constructed.
Memory allocator interface.
Source interface.
Root namespace.
Non-copyable object.
Various units used in packets.
Sink and source config.
Commonly used types and functions.
Sink and source config.
Definition: config.h:22
Unique ownrship pointer.